var pl_x;
var b_x = 0, b_y = 0, b_alpha;
var b_max_y;
var pl_add;
var started, speed, speed_x, speed_y, score;
HEIGHT = 450;
WIDTH = 300;

function gameOver(s){
	alert(s);
	newGame();
}

function scanAroundBall(){
	
	if((b_y+b_r)>HEIGHT)
		gameOver('Game Over');

	if(( (b_x+b_r)>WIDTH ) || ( (b_x-b_r)<0 ))
		speed_x=0-speed_x;
	if  ( (b_y-b_r)<0 )
		speed_y=0-speed_y;
		//rotateBall();
	if (( (b_y+b_r)<HEIGHT-topValue-pl_h ) && ( (b_y+b_r+speed+2)>HEIGHT-topValue-pl_h )){
		if ( (b_x>pl_x-b_r) && (b_x<(pl_x+pl_w+b_r)) ){					//совпадение х шара и платформы
			//if (Math.random()>0.5)
				////b_alpha=135;
			//else
				//b_alpha=45;
			speed_y = -Math.abs(speed_y);
		}
	}
}

function moveBall(){
	scanAroundBall();
	/*if(b_alpha==45){
		b_x++;
		b_y--;
	}
	else if(b_alpha==135){
		b_x--;
		b_y--;
	}
	else if(b_alpha==225){
		b_x--;
		b_y++;
	}
	else if(b_alpha==315){
		b_x++;
		b_y++;
	}
//*/	
	b_x+=speed_x;
	b_y+=speed_y;
//	scanAroundBall();
}

function initGame(){
	score=0;
	pl_add=false;
	topValue=0;
	speed=1;
	b_alpha = .7; 
	speed_x=speed*Math.cos(b_alpha);
	speed_y=-speed*Math.sin(b_alpha);
	b_r=5;
	pl_x=145;
	pl_w=100;
	b_x=150;
	b_max_y=HEIGHT-pl_h-b_r;
	b_y=b_max_y-1;
	b_alpha=Math.PI/4;
	started=false;
}
